package com.sharding.jdbc.mybatis.algorithm;

import io.shardingsphere.core.api.algorithm.sharding.ShardingValue;
import io.shardingsphere.core.api.algorithm.sharding.complex.ComplexKeysShardingAlgorithm;

import java.util.Collection;
import java.util.LinkedList;
import java.util.List;

public class Value2DataSourceAlgorithm implements ComplexKeysShardingAlgorithm {
    @Override
    public Collection<String> doSharding(Collection<String> availableTargetNames, Collection<ShardingValue> shardingValues) {
//        System.out.println("************ datasourceNames="+availableTargetNames);
//        System.out.println("************ shardingValues="+shardingValues);

        List<String> targetDataSources = new LinkedList<>();

        String logicDataSourceName = String.valueOf(availableTargetNames.toArray()[0]);

        for (ShardingValue value : shardingValues) {
            targetDataSources.add(logicDataSourceName);
        }

        return targetDataSources;
    }
}
